<template>
  <div>
    代码在 < script > 里
    <div>测试数据 ---- {{ objVal }}</div>
  </div>
</template>

<script>
// 深度克隆，涉及多种数据类型的
function deepClone(origin, target) {
  var target = target || {};
  var toStr = Object.prototype.toString;
  var arrStr = "[object Array]";
  for (let prop in origin) {
    if (origin.hasOwnProperty(prop)) {
      if (typeof origin[prop] == "object" && origin[prop] !== null) {
        if (toStr.call(origin[prop]) == arrStr) {
          origin[prop] = [];
        } else {
          origin[prop] = {};
        }
        deepClone(origin[prop], target[prop]);
      } else {
        target[prop] = origin[prop];
      }
    }
  }
  return target;
}
// 通过Object.assign 实现
const deepClone1 = obj => {
  var proto = Object.getPrototypeOf(obj);
  return Object.assign({}, Object.create(proto), obj);
};
//通过 JSON.parse(JSON.stringify(obj))

export default {
  data() {
    return {
      objVal:
        "{'age': 18, 'name': 'ff', 'hobby': ['basketball', 'cook', 'food'], 'h': {'go': 'home', 'to': 'park'}}"
    };
  }
};
</script>
